package com.pgybook.db.entity.mapper;

import org.springframework.stereotype.Repository;
import com.pgybook.db.entity.domain.BookOrder;
import com.pgybook.db.entity.domain.BookOrderEx;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.Update;

@Repository
public interface BookOrderMapper {
    int countByExample(BookOrderEx example);

    int deleteByExample(BookOrderEx example);

    @Delete({
            "delete from bookorder",
            "where ORDERID = #{orderid,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long orderid);

    @Insert({
            "insert into bookorder (CUSTID, LIBID, ",
            "IPADDRESS, EXPCOMID, ",
            "ID, EXPNO, WEIGHT, ",
            "POSTAGE, STATUS, ",
            "DELIVERADDRESS, CONTACT, ",
            "PHONE, ZIPCODE, ",
            "CRTTIME, UPDTIME, ",
            "DELIVERTIME)",
            "values (#{custid,jdbcType=BIGINT}, #{libid,jdbcType=INTEGER}, ",
            "#{ipaddress,jdbcType=VARCHAR}, #{expcomid,jdbcType=INTEGER}, ",
            "#{id,jdbcType=INTEGER}, #{expno,jdbcType=VARCHAR}, #{weight,jdbcType=INTEGER}, ",
            "#{postage,jdbcType=DECIMAL}, #{status,jdbcType=INTEGER}, ",
            "#{deliveraddress,jdbcType=VARCHAR}, #{contact,jdbcType=VARCHAR}, ",
            "#{phone,jdbcType=VARCHAR}, #{zipcode,jdbcType=VARCHAR}, ",
            "#{crttime,jdbcType=TIMESTAMP}, #{updtime,jdbcType=TIMESTAMP}, ",
            "#{delivertime,jdbcType=TIMESTAMP})"
    })
    @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "orderid", before = false, resultType = Long.class)
    int insert(BookOrder record);

    int insertSelective(BookOrder record);

    List<BookOrder> selectByExample(BookOrderEx example);

    @Select({
            "select",
            "ORDERID, CUSTID, LIBID, IPADDRESS, EXPCOMID, ID, EXPNO, WEIGHT, POSTAGE, STATUS, ",
            "DELIVERADDRESS, CONTACT, PHONE, ZIPCODE, CRTTIME, UPDTIME, DELIVERTIME",
            "from bookorder",
            "where ORDERID = #{orderid,jdbcType=BIGINT}"
    })
    @ResultMap("BaseResultMap")
    BookOrder selectByPrimaryKey(Long orderid);

    int updateByExampleSelective(@Param("record") BookOrder record, @Param("example") BookOrderEx example);

    int updateByExample(@Param("record") BookOrder record, @Param("example") BookOrderEx example);

    int updateByPrimaryKeySelective(BookOrder record);

    @Update({
            "update bookorder",
            "set CUSTID = #{custid,jdbcType=BIGINT},",
            "LIBID = #{libid,jdbcType=INTEGER},",
            "IPADDRESS = #{ipaddress,jdbcType=VARCHAR},",
            "EXPCOMID = #{expcomid,jdbcType=INTEGER},",
            "ID = #{id,jdbcType=INTEGER},",
            "EXPNO = #{expno,jdbcType=VARCHAR},",
            "WEIGHT = #{weight,jdbcType=INTEGER},",
            "POSTAGE = #{postage,jdbcType=DECIMAL},",
            "STATUS = #{status,jdbcType=INTEGER},",
            "DELIVERADDRESS = #{deliveraddress,jdbcType=VARCHAR},",
            "CONTACT = #{contact,jdbcType=VARCHAR},",
            "PHONE = #{phone,jdbcType=VARCHAR},",
            "ZIPCODE = #{zipcode,jdbcType=VARCHAR},",
            "CRTTIME = #{crttime,jdbcType=TIMESTAMP},",
            "UPDTIME = #{updtime,jdbcType=TIMESTAMP},",
            "DELIVERTIME = #{delivertime,jdbcType=TIMESTAMP}",
            "where ORDERID = #{orderid,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(BookOrder record);
}
